<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Route;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public $role_action = array(
        1 => ['ClientController@clientList','ProjectController@projectList','LoginController@index'],
        2 => ['ProductController@index','ProductCategoryController@cateList','LoginController@index'],
        3 => ['ClientCaseController@index','OrderController@orderList','LoginController@index'],
    );
    public function handle($request, Closure $next)
    {
        if (!session('user')) {
            return redirect('/login');
        }
        $RouteAction = Route::currentRouteAction();
        $RouteAction = explode("\\",$RouteAction);
        $RouteAction = array_last($RouteAction);
        $role_ids = session('user');
        $role_ids = $role_ids['role_ids'];
        $role_action = $this->role_action;
        foreach ($role_ids as $rid){
//            if(!in_array($RouteAction,$role_action[intval($rid)])){
//                return back()->with('msg','权限不足,如有需要，请联系管理员');
//            }
        }
        return $next($request);
    }
}
